o
    Nis                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm  m	Z
 ddlmZ dZdZG d	d
 d
ejjZG dd dejjZdS )z2SCV dataset from http://arxiv.org/abs/1812.01717 .    )absolute_import)division)print_function)loggingNz0https://storage.googleapis.com/scv_dataset/data/a  @article{DBLP:journals/corr/abs-1812-01717,
  author    = {Thomas Unterthiner and
               Sjoerd van Steenkiste and
               Karol Kurach and
               Rapha{"{e}}l Marinier and
               Marcin Michalski and
               Sylvain Gelly},
  title     = {Towards Accurate Generative Models of Video: {A} New Metric and
               Challenges},
  journal   = {CoRR},
  volume    = {abs/1812.01717},
  year      = {2018},
  url       = {http://arxiv.org/abs/1812.01717},
  archivePrefix = {arXiv},
  eprint    = {1812.01717},
  timestamp = {Tue, 01 Jan 2019 15:01:25 +0100},
  biburl    = {https://dblp.org/rec/bib/journals/corr/abs-1812-01717},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}
c                       s(   e Zd ZdZejj fddZ  ZS )StarcraftVideoConfigz"Config for StarcraftVideo dataset.c                    s:   t t| jddtjddi| || _|| _|| _d S )Nversionz1.0.0z6New split API (https://tensorflow.org/datasets/splits) )	superr   __init__tfdscoreVersionmap_name
resolution
size_in_gb)selfr   r   r   kwargs	__class__r   W/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/video/starcraft.pyr
   7   s   
zStarcraftVideoConfig.__init__)	__name__
__module____qualname____doc__r   r   disallow_positional_argsr
   __classcell__r   r   r   r   r   4   s    r   c                   @   s   e Zd ZdZeddddddedd	dd
ddeddddddedddd
ddeddddddedddd
ddeddddddedddd
ddgZdd Zd d! Zd"d# Zd$d% Z	d&S )'StarcraftVideozStarcraft video datasets.brawl_64z Brawl map with 64x64 resolution.Brawl@   g333333@)namedescriptionr   r   r   	brawl_128z"Brawl map with 128x128 resolution.   g333334@collect_mineral_shards_64z/CollectMineralShards map with 64x64 resolution.CollectMineralShardscollect_mineral_shards_128z1CollectMineralShards map with 128x128 resolution.move_unit_to_border_64z+MoveUnitToBorder map with 64x64 resolution.MoveUnitToBorderg333333@move_unit_to_border_128z-MoveUnitToBorder map with 128x128 resolution.road_trip_with_medivac_64z.RoadTripWithMedivac map with 64x64 resolution.RoadTripWithMedivacg333333@road_trip_with_medivac_128z0RoadTripWithMedivac map with 128x128 resolution.g@c                 C   s@   t jdt jjd | jj| jjdfdi}t jj| d|dtdS )N
rgb_screen   )shapez7This data set contains videos generated from Starcraft.z6https://storage.googleapis.com/scv_dataset/README.html)builderr!   featureshomepagecitation)	r   r1   FeaturesDictVideobuilder_configr   r   DatasetInfo	_CITATION)r   r1   r   r   r   _info   s   zStarcraftVideo._infoc                    s   t d| jj| jj| jjf    fddtdD } d |d<  d |d< ||}tjjtj	j
d	d
d | D idtjjtj	jd	|d gidtjjtj	jd	|d gidgS )Nz%s_%dx%d_png/c                    s   i | ]}d |  d|  qS )ztrain_%dztrain-0000%d-of-00010.tfrecordsr   ).0iurlr   r   
<dictcomp>   s    z4StarcraftVideo._split_generators.<locals>.<dictcomp>
   zvalid-00000-of-00001.tfrecordsvalidztest-00000-of-00001.tfrecordstestfilesc                 S   s   g | ]
\}}d |v r|qS )trainr   )r:   r    downloadr   r   r   
<listcomp>   s
    z4StarcraftVideo._split_generators.<locals>.<listcomp>)r    
gen_kwargs)DATA_URL_DIRr6   r   r   rangedownload_and_extractr   r   SplitGeneratorSplitTRAINitemsTEST
VALIDATION)r   
dl_managerurls_to_downloaddownloaded_urlsr   r<   r   _split_generators   s4   


z StarcraftVideo._split_generatorsc                 C   s   t jdgt jt jdgt jt jdgt jt jdgt jd}dt jg t ji}t jj|||d\}}t jt j	j
|d t jd}|S )zParses single video from the input tfrecords.

    Args:
      example_proto: tfExample proto with a single video.

    Returns:
      dict with all frames, positions and actions.
          )game_duration_loopsgame_duration_secondsn_stepsscreen_sizer-   )context_featuressequence_features)dtype)tfioFixedLenFeatureint64float32FixedLenSequenceFeaturestringparse_single_sequence_examplemap_fnimage
decode_pnguint8)r   example_protorZ   r[   _seq_featvideo_framesr   r   r   _parse_single_video   s    

z"StarcraftVideo._parse_single_videoc              
   c   s
   t dd| t  k tjt|}|j	| j
tjjjd}tjjj| }tjj 7}|tjj  zd}	 ||}|d|ifV  |d7 }qB tjjyj   Y W d    W d    d S w 1 snw   Y  W d    d S 1 s~w   Y  d S )NzReading data from %s.,)num_parallel_callsr   Tr-   rT   )r   infojoinr]   Graph
as_defaultdataTFRecordDatasetsortedmaprm   experimentalAUTOTUNEcompatv1make_one_shot_iteratorget_nextSessionrunglobal_variables_initializererrorsOutOfRangeError)r   rB   dsiteratorsessr;   videor   r   r   _generate_examples   s2   
"z!StarcraftVideo._generate_examplesN)
r   r   r   r   r   BUILDER_CONFIGSr9   rS   rm   r   r   r   r   r   r   B   s~    ;r   )r   
__future__r   r   r   abslr   tensorflow.compat.v2rz   v2r]   tensorflow_datasets.public_api
public_apir   rG   r8   r   BuilderConfigr   GeneratorBasedBuilderr   r   r   r   r   <module>   s   